﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 称重添加 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>
    
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">


                <label class="layui-form-label">称重日期</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="date" id="weighDate" lay-verify="date" autocomplete="off" class="layui-input">
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">羊只耳号</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <select id="earBugles">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">称重类型</label>
                    <div class="layui-input-block">
                        <select id="weightType" lay-filter="testSelect2">
                            <option value="">请选择</option>
                            <option value="断奶重">断奶重</option>
                            <option value="月龄重">月龄重</option>
                            <option value="出生重">出生重</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">品种</label>
                    <div class="layui-input-block">
                        <select id="variety" lay-filter="testSelect2">
                            <option value="">请选择</option>
                            <option value="杜泊">杜泊</option>
                            <option value="澳洲白">澳洲白</option>
                            <option value="萨福克">萨福克</option>
                            <option value="杜湖">杜湖</option>
                            <option value="杜杜湖">杜杜湖</option>
                            <option value="萨杜湖">萨杜湖</option>
                            <option value="澳湖">澳湖</option>
                            <option value="湖羊">湖羊</option>
                            <option value="澳杜湖">澳杜湖</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">重量(公斤)</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="weight" lay-verify="required" autocomplete="off" lay-reqtext="请输入" lay-affix="clear" class="layui-input demo-phone">
                    </div>
                </div>


                <button type="button" class="layui-btn layui-bg-red" onclick="Add()" lay-on="test-iframe-curl">新增</button>

            </div>
        </div>


        </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use(['table'], function () {
             var table = layui.table;
             var form = layui.form;
             var layer = layui.layer;

         });

    </script>


</body>

</html>
<script>
    var form = layui.form;
    var $ = layui.jquery;

    $(function () {
        bangsheng();
    })
    function bangsheng() {

        $.ajax({
            url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
            data: JSON.stringify({}),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res)
                $.each(res.data, function () {
                    $("#earBugles").append(`<option value="${this.recordId}">${this.recordAuricle}</option>`);
                })
                form.render('select'); // 重新渲染下拉框

            }

        })
    }
    function Add() {
            var data = {
            weighDate: $("#weighDate").val(),
            sheepNumber: $("#earBugles").val(),
            weightType: $("#weightType").val(),
            weight: $("#weight").val(),
            variety: $("#variety").val(),
            
            }
            console.log(data)
        $.ajax({
            
            url: "http://localhost:5269/api/SheepArchive/SheepWeighedCreate",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.msg('添加成功')
                        location.href = "/Breesing/SheepWeighing/"
                    }
                    else {
                        layer.msg('保存失败')
                    }
                }
            })
        }
</script>